package dataflow.core;

import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;

import org.apache.log4j.Logger;

public class Task extends PE{

	static Logger log = Logger.getLogger(Task.class);
	
	public Task(dataflowScheme.Task etask, LinkedBlockingQueue<IEvent> queue, LinkedBlockingQueue<ExecutionEvent> executionQueue){
		super(etask, queue, executionQueue);
	}

	protected Queue<Integer> iterationQueue = new LinkedList<Integer>();
	
	protected void run(int portset) {
		ExecutionEvent event = new TaskExecutionEvent(this, portset);
		executionQueue.offer(event);
	}

	protected void invokeNextIteration(int portSet){
		if(sourceInstance != null){
			//plan iteration
			iterationQueue.add(portSet);
		} else {
			run(portSet);
		}
	}
	
	protected Integer getNextPortset2invokeRun(){
		return iterationQueue.poll();
	}

	@Override
	protected void endOfSourceRun() {
		sourceInstance = null;		
	}
}
